package cc.lj.internal.merchant.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.merchant.domain.contract.repository.IProperyResourcesRepository;
import cc.lj.internal.merchant.infrastructure.dao.IPropertyResourcesMapper;
import cc.lj.internal.merchant.infrastructure.exception.MerchantExceptionEnum;
import cc.lj.internal.merchant.infrastructure.po.PropertyResourcesPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 物业资源展位表　Mysql仓储实现
 * @author liangxifeng
 * @date 2021-12-24
 */
@Repository("propertyResourcesMysqlRespository")
public class PropertyResourcesMysqlRespository implements IProperyResourcesRepository, BasePageHelper<PropertyResourcesPO> {
    @Autowired
    private IPropertyResourcesMapper propertyResourcesMapper;

    @Override
    public PropertyResourcesPO getById(Integer id) {
        PropertyResourcesPO propertyResourcesPO = propertyResourcesMapper.selectById(id);
        if(propertyResourcesPO == null)
        {
            throw new ServiceException(MerchantExceptionEnum.GET_ONE_PROPERTY_RESOURCE_FAILED);
        }
        return propertyResourcesPO;
    }

    @Override
    public List<PropertyResourcesPO> list(PropertyResourcesPO param) {
        QueryWrapper<PropertyResourcesPO> wrapper = new QueryWrapper<>(param);
        List<PropertyResourcesPO> entitys = propertyResourcesMapper.selectList(wrapper);
        if(entitys == null)
        {
            throw new ServiceException(MerchantExceptionEnum.PROPERTY_RESOURCES_LIST_NULL);
        }
        return entitys;
    }
}
